<template>
  <div class="cart-item">
    <div class="cart-select">
      <check-button
        :isSelect="product.checked"
        @click.native="checkClick(product)"
      />
    </div>
    <div class="cart-image">
      <img :src="product.image" alt="" />
    </div>
    <div class="cart-info">
      <div class="title">{{ product.title }}</div>
      <div class="desc">商品描述：{{ product.desc }}</div>
      <div class="price">
        <span>￥ {{ product.price }}</span>
        <div class="count">
          <button class="add" @click="addClick(product)">+</button>
          <span>{{ product.count }}</span>
          <button class="sub" @click="subClick(product)">-</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import CheckButton from "@/views/cart/chil/CheckButton";
export default {
  name: "CartListitem",
  props: {
    product: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  components: {
    CheckButton,
  },

  methods: {
    checkClick(product) {
      product.checked = !product.checked;
    },
    addClick(product) {
      product.count += 1;
    },
    subClick(product) {
      if (product.count > 1) {
        product.count -= 1;
      } else {
        // this.$toast.show("商品数量不能再减少啦", 1500);
        console.log("商品数量不能再减少啦");
      }
    },
  },
};
</script>

<style scoped>
.cart-item {
  display: flex;
  /* 元素位于容器的中心 */
  align-items: center;
  padding: 10px 8px;
  border-bottom: 3px solid rgba(100, 100, 100, 0.1);
}
.cart-image {
  margin: 0 8px;
}
.cart-image img {
  width: 70px;
  height: 90px;
  border-radius: 8px;
}

.cart-info {
  overflow: hidden;
}
.cart-info .title {
  color: #333;
  margin-bottom: 20px;
  font-size: 16px;
}
.cart-info .desc {
  font-size: 12px;
  margin-bottom: 20px;
}
.title,
.desc {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.price {
  display: flex;
  justify-content: space-between;
}

.price span {
  color: rgba(250, 131, 51, 0.842);
}

.count button {
  margin: 0 5px;
  width: 20px;
  height: 20px;
  line-height: 10px;
  color: var(--color-high-text);
  background-color: #fff;
  border: 1px solid #999;
  border-radius: 5px;
  text-align: center;
  vertical-align: middle;
}

.count span {
  color: var(--color-high-text);
}
</style>